<!--
 * @Author: ChunLai
 * @Date: 2022-03-28 18:29:48
 * @LastEditTime: 2025-11-25 14:13:17
 * @Description: 保障责任
 * @FilePath: \01.latest-short-insure\src\views\index\components\InsurDutyDesc.vue
-->
<template>
  <div class="pd14_lr bg-fff">
    <div class="sy-mode-head">
      <span class="sy-mode-head-label">保障责任</span>
    </div>
    <ol class="item-ol">
      <li class="item-li" v-for="(item, index) in dutysList" :key="index">
        <span class="item-li-l">
          {{ item.dutyName }}
        </span>
        <span class="item-li-r" @click="showDutyItem(item)">
          <van-icon name="arrow" />
        </span>
      </li>
    </ol>
    <div class="item-li-more" @click="showAll = !showAll" v-if="dutysLen > 3">
      全部{{ dutysLen }}项保障
      <van-icon
        :name="showAll ? 'arrow-up' : 'arrow-down'"
        color="#666"
        size="12"
        class="ml4"
      />
    </div>

    <PopCommon
      popTitle="保障详情"
      :popShow="showPreModule"
      @callback="showPreModule = false"
    >
      <template v-slot:content>
        <ol class="item-ol pd14_lr">
          <li
            class="item-li2"
            v-for="(item, index) in zeRenList"
            :key="`detail${index}`"
          >
            <div class="item-li-t">
              <span class="item-li-l flex_1 font3 mr10">
                {{ item.dutyName }}
              </span>
              <span class="item-li-r2" v-if="item.value">
                {{ item.value }}
              </span>
            </div>
            <div
              class="item-li-b"
              v-html="item.dutyDescribe"
              v-if="item.dutyDescribe"
            ></div>
          </li>
        </ol>
      </template>
    </PopCommon>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "InsureDutyDesc",
  data() {
    return {
      showPreModule: false,
      item: {},
      showAll: false,
    };
  },
  components: {},
  computed: {
    ...mapGetters({
      dutys: "varietyInfo/dutys",
      dutysConfig: "page/dutysConfig",
    }),
    zeRenList() {
      let res = this.dutys;
      if (this.dutysConfig.length > 0) {
        res = this.dutysConfig;
      }
      return res;
    },
    dutysLen() {
      let res = 0;
      if (this.zeRenList.length > 0) {
        res = this.zeRenList.length;
      }
      return res;
    },
    dutysList() {
      let res = [];
      if (this.zeRenList.length > 0) {
        if (this.showAll) {
          res = this.zeRenList;
        } else {
          res = this.zeRenList.slice(0, 3);
        }
      }
      return res;
    },
  },
  mounted() {
    // 排序
    this.dutys.sort((a, b) => a.id - b.id);
  },
  methods: {
    showDutyItem(item) {
      this.item = item;
      this.showPreModule = true;
    },
  },
};
</script>

<style lang="less" scoped>
.item-ol {
  display: flex;
  flex-direction: column;

  .item-li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 0;
    font-size: 15px;
    line-height: 22px;
    font-weight: 400;

    .item-li-l {
      width: calc(100% - 130px);
    }

    .item-li-r {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      width: 80px;
      line-height: 18px;
      font-size: 14px;
      color: #747474;
      .value-str {
        width: calc(100% - 14px);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: right;
      }
    }
  }

  .item-li2 {
    padding-bottom: 10px;

    &:not(:last-child) {
      border-bottom: 1px dashed #e1e1e1;
    }

    .item-li-t {
      display: flex;
      justify-content: space-between;
      width: 100%;
      padding-top: 8px;

      .item-li-l {
        line-height: 1.3;
        color: #333333;
      }

      .item-li-r2 {
        max-width: 40%;
        line-height: 1.3;
        color: #ff8c2c;
        text-align: right;
      }
    }

    .item-li-b {
      color: #666;
      font-size: 12px;
      line-height: 1.5;
      margin-top: 8px;
      /deep/strong {
        color: #1b1b1b;
      }
    }
  }
}
.item-li-more {
  display: flex;
  align-items: center;
  padding: 10px 0;
  font-size: 15px;
  font-weight: 500;
  line-height: 19.89px;
  color: #e7a249;
}
</style>
